class OsnDapp {
    func fromJson(_ json:[String:Any]) ->DMCCDapp {
        let dapp = DMCCDapp()
        dapp.type = OsnDappType(rawValue: json["type"] as? Int ?? 0)
        dapp.serviceId = json["serviceId"] as? String ?? ""
        dapp.name = json["name"] as? String ?? ""
        dapp.displayName = json["displayName"] as? String ?? ""
        dapp.portrait = json["portrait"] as? String ?? ""
        dapp.theme = json["theme"] as? String ?? ""
        dapp.url = json["url"] as? String ?? ""
        dapp.info = json["info"] as? String ?? ""
        dapp.param = json["param"] as? String ?? ""
        dapp.urlParam = json["urlParam"] as? String ?? ""
        dapp.fromUser = json["fromUser"] as? String ?? ""
        dapp.shareId = json["shareId"] as? String ?? ""
        dapp.target = json["target"] as? String ?? ""
        return dapp
    }
    func getDappInfo(_ osnId:String) ->DMCCDapp? {
        return dbDapp.getDappInfo(osnId)
    }
    func setDappInfo(_ info:DMCCDapp) -> Bool{
        return dbDapp.addDappInfo(info)
    }
    func fetchDappInfo(_ osnId:String) async ->DMCCDapp? {
        print("fetchDappInfo: \(osnId)")
        guard let info = await gimService.imRequest("GetServiceInfo", osnId, nil) else {return nil}
        guard let result = gimService.getResult(info) else {return nil}
        let dapp = fromJson(result)
        _ = setDappInfo(dapp)
        return dapp
    }
    func setDappInfoFromJson(info:[String:Any]){
        let dapp = fromJson(info)
        _ = setDappInfo(dapp)
    }

}
let gosnDapp = OsnDapp()
